package admin.action.statistics;
import teacher.bean.Teacher;
import admin.service.member.LeaderServiceAdmin;

import java.text.Collator;
import java.util.*;

public class MemberStatisticsAction
{
	
	 List<Map> lists0=new ArrayList<Map>();
	 List<Map> lists02=new ArrayList<Map>();
	 List<Map> lists03=new ArrayList<Map>();
	 
	 List<Map> lists1=new ArrayList<Map>();
	 List<Map> lists12=new ArrayList<Map>();
	 List<Map> lists13=new ArrayList<Map>();
	 
	 List<Map> lists2=new ArrayList<Map>();
	 List<Map> lists22=new ArrayList<Map>();
	 List<Map> lists23=new ArrayList<Map>();
	 
	 List<Map> lists3=new ArrayList<Map>();
	 List<Map> lists32=new ArrayList<Map>();
	 List<Map> lists33=new ArrayList<Map>();
	 

	public List<Map> getLists22() {
		return lists22;
	}
	public void setLists22(List<Map> lists22) {
		this.lists22 = lists22;
	}
	public List<Map> getLists12() {
		return lists12;
	}
	public void setLists12(List<Map> lists12) {
		this.lists12 = lists12;
	}
	public List<Map> getLists02() {
		return lists02;
	}
	public void setLists02(List<Map> lists02) {
		this.lists02 = lists02;
	}
	public List<Map> getLists32() {
		return lists32;
	}
	public void setLists32(List<Map> lists32) {
		this.lists32 = lists32;
	}


	public String execute()
	{
	/*方向0开始*/
		LeaderServiceAdmin ls=new LeaderServiceAdmin();
		 Teacher tea=new Teacher();
		 tea.setDirection(0);
		lists0=ls.getDirectionName(tea);
	
		String a[] = new String[lists0.size()];	
		for(int i=0;i<lists0.size();i++)
		{			
			Map map=lists0.get(i);					
			a[i]=(String) map.get(1);		
		}
		Arrays.sort(a, Collator.getInstance(java.util.Locale.CHINA));//升序; 		
		System.out.println(Arrays.toString(a)); 
		
		for(int i=0;i<lists0.size();i++)
		{	
			
			try {
				if(lists0.get(i).get(14).equals("1"))
				{					
					Map map4=new HashMap();	
					map4.put(1, lists0.get(i).get(1)+"(组长)");
					map4.put(2, lists0.get(i).get(2));
					lists02.add(map4);				
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}	
			int p=0;			
			Map mapx0=new HashMap();
			Map mapy0=new HashMap();
			for(int i=0;i<a.length;i++)
			{
				
				int flag=0;
				
				for(int j=0;j<lists02.size();j++)
				{
					if(!(lists02.get(j).get(1).toString().contains(a[i])))
						flag++;										
				}

				if(lists02.size()==flag)			
				{
						
						Teacher tea3=new Teacher();
						tea3.setName(a[i]);
						lists03=ls.getUserFromName(tea3);	
					if(lists03.size()!=1)
					{		
						//System.out.println("我是老贺");
						for(int k=0;k<lists03.size();k++)
						{
							Map map3=lists03.get(k);
							mapx0.put(p, map3.get(1));
							mapy0.put(p, map3.get(2));						
							p++;
							i++;
						}											
					}

					else
						{
							Map map3=lists03.get(0);	
							mapx0.put(p, a[i]);
							mapy0.put(p, map3.get(2));	
							p++;
						}				
				}
				else
				{
					Teacher tea4=new Teacher();
					tea4.setName(a[i]);
					lists03=ls.getUserFromName(tea4);	
				if(lists03.size()!=1)
				{	for(int k=0;k<lists03.size();k++)
					{
						i++;
						Map map3=lists03.get(k);
						try {
							if(!map3.get(14).equals("1"))
							{	
								System.out.println("老贺的权限值"+map3.get(14));
								mapx0.put(p, map3.get(1));
								mapy0.put(p, map3.get(2));
								p++;
								
							}
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
					//	i=i+lists03.size()-lists02.size();
					}	
				i=i-1;
				}					
				}
			}	
			for(int a1=0;a1<mapx0.size();a1++)
			{
				Map map=new HashMap();				
				map.put(1,mapx0.get(a1));
				map.put(2,mapy0.get(a1));					
				lists02.add(map);
			}
			/*方向0结束*/
		//方向1开始
			LeaderServiceAdmin ls1=new LeaderServiceAdmin();
			 Teacher tea1=new Teacher();
			 tea1.setDirection(1);
			lists1=ls1.getDirectionName(tea1);
			String b[] = new String[lists1.size()];	
			for(int i=0;i<lists1.size();i++)
			{			
				Map map=lists1.get(i);					
				b[i]=(String) map.get(1);		
			}
			Arrays.sort(b, Collator.getInstance(java.util.Locale.CHINA));//升序; 		
			//System.out.println(Arrays.toString(a)); 
			
			for(int i=0;i<lists1.size();i++)
			{
				try {
					try {
						if(lists1.get(i).get(14).equals("1"))
						{
							Map map5=new HashMap();
							map5.put(1, lists1.get(i).get(1)+"(组长)");
							map5.put(2, lists1.get(i).get(2));
							lists12.add(map5);		
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					
					e.printStackTrace();
					break;
				}				
			}
				int p1=0;				
			Map mapx1=new HashMap();
			Map mapy1=new HashMap();
				for(int i=0;i<lists1.size();i++)
				{					
					int j=0;
					for(int k=0;k<lists12.size();k++)
					{
						if(!(lists12.get(k).get(1).toString().contains(b[i])))
							j++;
					}
					if(j==lists12.size())
					{
						Teacher tea3=new Teacher();
						tea3.setName(b[i]);
						lists13=ls1.getUserFromName(tea3);	
						if(lists13.size()>1)
						{
							for(int k=0;k<lists13.size();k++)
							{
								Map map3=lists13.get(k);
								mapx1.put(p1, map3.get(1));
								mapy1.put(p1, map3.get(2));
								p1++;		
								i++;
							}								
						}
						else							
							{
								Map map3=lists13.get(0);
								mapx1.put(p1, map3.get(1));
								mapy1.put(p1, map3.get(2));
								p1++;																		
							}
					}
					else
					{
							Teacher tea4=new Teacher();
							tea4.setName(b[i]);
							lists13=ls.getUserFromName(tea4);	
						if(lists13.size()!=1)
						{	for(int k=0;k<lists13.size();k++)
							{
								Map map3=lists13.get(k);
								try {
									if(!map3.get(14).equals("1"))
									{	
										i++;
										System.out.println("老贺的权限值"+map3.get(14));
										mapx1.put(p1, map3.get(1));
										mapy1.put(p1, map3.get(2));
										p1++;
										
									}
								} catch (Exception e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}	
						i=i-1;
						}						
					}					
				}
				for(int a1=0;a1<mapx1.size();a1++)
				{
					Map map=new HashMap();				
					map.put(1,mapx1.get(a1));
					map.put(2,mapy1.get(a1));					
					lists12.add(map);
				}
				//map5.put(1, "徐建明（组长）");
				//方向1结束
			//方向2开始
				LeaderServiceAdmin ls2=new LeaderServiceAdmin();
				 Teacher tea2=new Teacher();
				 tea2.setDirection(2);
				lists2=ls2.getDirectionName(tea2);
				String c[] = new String[lists2.size()];	
			for(int i=0;i<lists2.size();i++)
				{			
					Map map=lists2.get(i);					
					c[i]=(String) map.get(1);		
				}
				Arrays.sort(c, Collator.getInstance(java.util.Locale.CHINA));//升序; 		
				//System.out.println(Arrays.toString(a));
			
				for(int i=0;i<lists2.size();i++)
				{
					try {
						if(lists2.get(i).get(14).equals("1"))
						{
							Map map6=new HashMap();
							map6.put(1, lists2.get(i).get(1)+"(组长)");
							map6.put(2, lists2.get(i).get(2));
							lists22.add(map6);		
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
				int p2=0;			
				Map mapx2=new HashMap();
				Map mapy2=new HashMap();
					for(int i=0;i<lists2.size();i++)
					{
						int n=0;
						for(int j=0;j<lists22.size();j++)
						{
							if(!lists22.get(j).get(1).toString().contains(c[i]))
								n++;
						}
							if(n==lists22.size())
							{
								Teacher tea3=new Teacher();
								tea3.setName(c[i]);
								lists23=ls2.getUserFromName(tea3);		
								if(lists23.size()!=1)
								{
									for(int k=0;k<lists23.size();k++)
									{
										Map map3=lists23.get(k);								
										mapx2.put(1, map3.get(1));
										mapy2.put(2, map3.get(2));	
										p2++;
										i++;
									}
								}
								else
								{
									Map map3=lists23.get(0);	
									mapx2.put(p2, c[i]);
									mapy2.put(p2, map3.get(2));	
									p2++;
								}				
							
							}
							else
							{
								Teacher tea4=new Teacher();
								tea4.setName(c[i]);
								lists23=ls.getUserFromName(tea4);	
							if(lists23.size()!=1)
							{	for(int k=0;k<lists23.size();k++)
								{
									i++;
									Map map3=lists23.get(k);
									try {
										if(!map3.get(14).equals("1"))
										{	
											System.out.println("老贺的权限值"+map3.get(14));
											mapx2.put(p2, map3.get(1));
											mapy2.put(p2, map3.get(2));
											p2++;
											
										}
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								}	
							i=i-1;							
							}	
							
							}
						}	
						for(int a1=0;a1<mapx2.size();a1++)
						{
							Map map=new HashMap();				
							map.put(1,mapx2.get(a1));
							map.put(2,mapy2.get(a1));					
							lists22.add(map);
						}
					
					//map6.put(1, "汤一平（组长）");
					//方向2结束
				//方向3开始
					LeaderServiceAdmin ls3=new LeaderServiceAdmin();
					 Teacher tea3=new Teacher();
					 tea3.setDirection(3);
					lists3=ls3.getDirectionName(tea3);
					String d[] = new String[lists3.size()];	
					for(int i=0;i<lists3.size();i++)
					{			
						Map map=lists3.get(i);					
						d[i]=(String) map.get(1);		
					}
					Arrays.sort(d, Collator.getInstance(java.util.Locale.CHINA));//升序; 		
					//System.out.println(Arrays.toString(a)); 
					
					for(int i=0;i<lists3.size();i++)
					{
						try {
							if(lists3.get(i).get(14).equals("1"))
							{
								Map map8=new HashMap();
								map8.put(1, lists3.get(i).get(1)+"(组长)");
								map8.put(2, lists3.get(i).get(2));
								lists32.add(map8);	
							}
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
					}
					int p3=0;			
					Map mapx3=new HashMap();
					Map mapy3=new HashMap();
			for(int i=0;i<lists3.size();i++)
			{
				
					int l=0;
					for(int k=0;k<lists32.size();k++)
					{
						if(!lists32.get(k).get(1).toString().contains(d[i]))
							l++;
					}
					if(l==lists32.size())
							
							{	
								Teacher tea5=new Teacher();
								tea5.setName(d[i]);
								lists33=ls.getUserFromName(tea5);	
								if(lists33.size()!=1)
								{		
									//System.out.println("我是老贺");
									for(int k=0;k<lists33.size();k++)
									{
										Map map3=lists33.get(k);
										mapx3.put(p3, map3.get(1));
										mapy3.put(p3, map3.get(2));						
										p3++;
										i++;
									}											
								}
								else
								{		Map map3=lists33.get(0);	
										mapx3.put(p3, d[i]);
										mapy3.put(p3, map3.get(2));	
										p3++;
								//if(!lists32.get(0).get(1).equals(map2.get(1)))
								}
							}
					else
					{
							Teacher tea4=new Teacher();
							tea4.setName(d[i]);
							lists33=ls.getUserFromName(tea4);	
							if(lists33.size()!=1)
							{	for(int k=0;k<lists33.size();k++)
								{
									i++;
									Map map3=lists33.get(k);
									try {
										if(!map3.get(14).equals("1"))
										{	
											System.out.println("老贺的权限值"+map3.get(14));
											mapx3.put(p3, map3.get(1));
											mapy3.put(p3, map3.get(2));
											p3++;
											
											
										}
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
									
								}			
							i=i-1;	
							}					
					}
				}	
				for(int a1=0;a1<mapx3.size();a1++)
				{
					Map map=new HashMap();				
					map.put(1,mapx3.get(a1));
					map.put(2,mapy3.get(a1));					
					lists32.add(map);
				}
			
					//	map8.put(1, "南余荣（组长）");
					//	方向3结束
		return "succ";
	}
		
}